<?php

/**
 * categoriaagua actions.
 *
 * @package    sf_sandbox
 * @subpackage categoriaagua
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class categoriaaguaActions extends sfActions
{
 
  public function executeShow(sfWebRequest $request)
  {
    $this->categoria_agua = Doctrine_Core::getTable('CategoriaAgua')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->categoria_agua);
    
  }
  public function executeIndex(sfWebRequest $request)
  {
    $this->categoria_aguas = $this->getPager(CategoriaAguaTable::getBuscarCategorias(""), $request->getGetParameter('page'), "CategoriaAgua");
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new CategoriaAguaForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new CategoriaAguaForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($categoria_agua = Doctrine_Core::getTable('CategoriaAgua')->find(array($request->getParameter('id'))), sprintf('Object categoria_agua does not exist (%s).', $request->getParameter('id')));
    $this->form = new CategoriaAguaForm($categoria_agua);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($categoria_agua = Doctrine_Core::getTable('CategoriaAgua')->find(array($request->getParameter('id'))), sprintf('Object categoria_agua does not exist (%s).', $request->getParameter('id')));
    $this->form = new CategoriaAguaForm($categoria_agua);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();
//
   $this->forward404Unless($categoria_agua = Doctrine_Core::getTable('CategoriaAgua')->find(array($request->getParameter('id'))), sprintf('Object categoria_agua does not exist (%s).', $request->getParameter('id')));
    $categoria_agua->delete();

    $this->redirect('categoriaagua/index');
  }
public function executeEliminar(sfWebRequest $request) {
           $this->forward404Unless($this->categoria_agua = Doctrine_Core::getTable('CategoriaAgua')->find(array($request->getParameter('id'))), sprintf('Object lectura does not exist (%s).', $request->getParameter('id')));
//        $this->form = new CategoriaAguaForm($categoria_agua);
              
    }
//    public function executeVer(sfWebRequest $request) {
//        $this->forward404Unless($categoria_agua = Doctrine_Core::getTable('CategoriaAgua')->find(array($request->getParameter('id'))), sprintf('Object categoria_agua does not exist (%s).', $request->getParameter('id')));
//        $this->form = new CategoriaAguaForm($categoria_agua);
//        //$this->form->setTipoForm('ver');
//    }
    
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $categoria_agua = $form->save();

      $this->redirect('categoriaagua/index');
    }
  }
   protected function getPager($q, $page, $model) {
        $pager = new sfDoctrinePager($model, sfConfig::get('app_nro_x_pagina_contribuyente'));
        $pager->setQuery($q);
        $pager->setPage($page);
        $pager->init();

        return $pager;
    }
     public function executeBuscarCategorias(sfWebRequest $request) {
        
        if ($request->isMethod('post')) {
            $nombre = $request->getPostParameter("nombre");
           } else {
            $nombre = $request->getGetParameter("nombre");
          }
        $this->categoria_aguas = $this->getPager(CategoriaAguaTable::getBuscarCategorias($nombre), $request->getGetParameter('page'), "CategoriaAgua");
        if ($request->isXmlHttpRequest()) {
            return $this->renderPartial("categoriaagua/listadocategorias", array('categoria_aguas' => $this->categoria_aguas));
        }
    }
}
